package com.egao.orderB.controller2;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.Driver;
import com.egao.orderB.service.DriverService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 司机管理
 * @author : Doman
 * @date : 2020-06-03 16:58:06
 * @version ：1.0
 */

//@Api(tags = "司机管理")
//@RestController
//@RequestMapping("/api/driver2")
public class DriverController extends BaseController {

	@Autowired
	private DriverService driverService;

	/**
	 * 分页查询列表
	 */
    @PreAuthorize("hasAuthority('orderB:driver:list')")
	@OperLog(value = "司机管理", desc = "分页查询")
    @ApiOperation("分页查询司机管理")
    @ApiPageParam
	@PostMapping("/page")
    public JsonResult list(PageResult2<T> page, Driver driver) throws Exception{
        return driverService.list(page, driver, getLoginUser());
    }

    /**
     * 查询全部司机管理
     */
    @PreAuthorize("hasAuthority('orderB:driver:list')")
    @OperLog(value = "司机管理", desc = "查询全部")
    @ApiOperation("查询全部司机管理")

    @PostMapping("/list")
    public JsonResult list(Driver driver){
        return driverService.list(driver, getLoginUser());
    }

    /**
     * 根据id查询司机管理
     */
    @PreAuthorize("hasAuthority('orderB:driver:list')")
    @OperLog(value = "司机管理", desc = "根据id查询")
    @ApiOperation("根据id查询司机管理")

    @PostMapping("/get")
    public JsonResult get(Driver driver) {
        return JsonResult.ok().setData(driverService.getById(driver));
		// 使用关联查询
        //PageParam<driver> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<driver> records = driverService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加司机管理
     */
//    @PreAuthorize("hasAuthority('orderB:driver:save')")
//    @OperLog(value = "司机管理", desc = "添加", param = false, result = true)
//    @ApiOperation("添加司机管理")
//
//    @PostMapping("/save")
//    public JsonResult save(Model model, Driver driver) {
//        return driverService.save(driver, getLoginUser());
//    }

    /**
     * 修改司机管理
     */
    @PreAuthorize("hasAuthority('orderB:driver:update')")
    @OperLog(value = "司机管理", desc = "修改", param = false, result = true)
    @ApiOperation("修改司机管理")

    @PostMapping("/update")
    public JsonResult update(Model model, Driver driver) {
        return driverService.update(driver, getLoginUser());
    }

    /**
     * 删除司机管理
     */
    @PreAuthorize("hasAuthority('orderB:driver:remove')")
    @OperLog(value = "司机管理", desc = "删除", result = true)
    @ApiOperation("删除司机管理")

    @PostMapping("/remove")
    public JsonResult remove(Driver driver ) {
        return driverService.remove(driver, getLoginUser());
    }

    /**
     * 批量添加司机管理
     */
    /**@RequiresPermissions("orderB:driver:save")
    @OperLog(value = "司机管理", desc = "批量添加", param = false, result = true)

    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Driver> list) {
        if (driverService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改司机管理
     */
    /**@RequiresPermissions("orderB:driver:update")
    @OperLog(value = "司机管理", desc = "批量修改", result = true)

    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Driver> batchParam) {
        if (batchParam.update(driverService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除司机管理
     */
    /**@RequiresPermissions("orderB:driver:remove")
    @OperLog(value = "司机管理", desc = "批量删除", result = true)

    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (driverService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
